package org.example.cet.demos.controller;


import jakarta.validation.Valid;
import org.example.cet.demos.converter.converter;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.Result;
import org.example.cet.demos.domain.form.ScoreBankForm;
import org.example.cet.demos.domain.po.ScoreBank;
import org.example.cet.demos.domain.query.ScoreBankQuery;
import org.example.cet.demos.service.impl.ScoreBankServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@RestController
@RequestMapping("/score-bank")
public class ScoreBankController {
    @Autowired
    private ScoreBankServiceImpl scoreBankService;
    @Autowired
    private converter converter;

    @PostMapping("/add")
    public Result add(@Valid @RequestBody ScoreBankForm scoreBankForm) {
        ScoreBank scoreBank = converter.ToScoreBank(scoreBankForm);
        scoreBankService.save(scoreBank);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        scoreBankService.removeById(id);
        return Result.success();
    }

    @PutMapping("/update/{id}")
    public Result update(@PathVariable String id, @Valid @RequestBody ScoreBankForm scoreBankForm) {
        ScoreBank scoreBank = converter.ToScoreBank(scoreBankForm);
        scoreBank.setId(id);
        scoreBankService.updateById(scoreBank);
        return Result.success();
    }

//    @GetMapping("/getPage")
//    public Result getPage(ScoreBankQuery scoreBankQuery) {
//        PageBean pb = scoreBankService.getPage(scoreBankQuery);
//        return Result.success(pb);
//    }
}
